package chapter04

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * author: yuhui
 * descriptions: WordCount实现第一种方式:map + reduceByKey
 * date: 2024 - 10 - 29 11:28 上午
 */
object WordCount1 {
  def main(args: Array[String]): Unit = {
    val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount1")

    val sc: SparkContext = new SparkContext(config)

    val lines: RDD[String] = sc.textFile("BookData/input/04data.txt")

    lines
      .coalesce(1)
      .flatMap(_.split("[，。、]"))
      .map((_, 1))
      .reduceByKey(_ + _)
      .collect()
      .foreach(println)
  }
}